$(function(){
		/*初始化表格*/
		$('#bidInviteReview').datagrid({
    		url:'backbidinvitereviewjson',
    		collapsible:true,
    		fit:true,
			fitColumns:true,
			toolbar:'#footer',
			pagination:true,
			pageSize:20,
			pageList:[20,50,100,200],
			remoteSort:false,
			onLoadSuccess:function(data){
		        if (data.total == 0) { 
				//colspan为实际显示的总列数，appendRow、mergeCells不用修改
				$(this).datagrid('appendRow', { inviteName: '<div style="text-align:center;color:red">没有相关记录！</div>' }).datagrid('mergeCells', { index: 0, field: 'inviteName', colspan: 10 }) 
				//隐藏分页导航条
				$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').hide(); 
				//隐藏选择框
				 $(this).datagrid('hideColumn', 'ck');
				} 
				//有数据时显示选择框、分页导航条
				else {
					$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').show();
					$(this).datagrid('showColumn', 'ck');}
		    },
   			columns:[[
   			 	{field:'ck',checkbox:true},
   			 	{field:'inviteID',hidden:'true'},
				{field:'inviteName',title:'招标名称',align:'center',width:'10%',
				formatter:function(value,row,index){
					if(row.inviteID == undefined)return row.inviteName;
					return'<a href="bidinviteinfo?iInviteID='+row.inviteID+'">'+row.inviteName+'</a>'
				}},
				{field:'type',title:'招标类型',align:'center',width:'8%',formatter: function(value,row,index){
	        	if(value == 0)
	        		return '公务';
	        	else if(value == 1)
	        		return '团建';
				else if(value == 2)
	        		return '业内';
				else
				return '私密游';
	        }},
				{field:'zoneName',title:'招标目的地',align:'center',width:'12%'},
				{field:'name',title:'联系人',align:'center',width:'10%'},
				{field:'tel',title:'联系方式',align:'center',width:'10%'},
				{field:'beginDate',title:'招标开始日期',align:'center',width:'10%',formatter:function(value) {
            var date = new Date(value);
            var year = date.getFullYear().toString();
            var month = (date.getMonth() + 1);
            var day = date.getDate().toString();
            if (month < 10) {
                month = "0" + month;
            }
            if (day < 10) {
                day = "0" + day;
            }
            return year + "-" + month + "-" + day;
        }},
				{field:'endDate',title:'招标结束日期',align:'center',width:'12%',formatter:function(value) {
            var date = new Date(value);
            var year = date.getFullYear().toString();
            var month = (date.getMonth() + 1);
            var day = date.getDate().toString();
            if (month < 10) {
                month = "0" + month;
            }
            if (day < 10) {
                day = "0" + day;
            }
            return year + "-" + month + "-" + day;
        }},
				{field:'budget',title:'预算金额',align:'center',width:'10%'},
				{field:'count',title:'参投数量',align:'center',width:'8%',formatter: function(value,row,index){
	        	if(value == "" || value==null)
	        		return '0';
	       
				else
				return value;
	        }},
				{field:'state',title:'发布状态',align:'center',width:'10%',formatter: function(value,row,index){
	        	if(value == 0)
	        		return '未发布';
	        	else if(value == 1)
	        		return '您的总团款低于2000元,不能发布';
				else if(value == 2)
	        		return '等待审核';
				else if(value == 3)
	        		return '已发布';
				else if(value == 4)
	        		return '审核不通过，请及时修改';
				
				else
				return '已结束';
	        }}
    		]]
		});
			
});
/*审核招标信息 2021.03.17 hanxl*/
function passBidInviteReview(){
	var rows = $('#bidInviteReview').datagrid('getSelections');
		var checkNum = rows.length;
		if(checkNum==0){
			$.messager.alert('错误','至少选择一项','error');
		 }else if(checkNum>1){
			$.messager.alert('错误','最多选择一项','error');
		 }else{
			var iInviteID = rows[0].inviteID;
			layer.confirm('请选择', {
			  btn: ['通过','驳回'] 
			}, function(){
			  reviewPost(iInviteID,3);
			}, function(){
			 reviewPost(iInviteID,4);
			});
	}
}
/* 审核请求 */
function reviewPost(iInviteID,accountState){
	var num=0;
	if(accountState==3){
		
layer.prompt({title: '请输入保证金额，并确认', formType: 1}, function(number, index){
  layer.close(index);
    layer.msg('保证金为：'+number);
num=number;
$.ajax({
		url:"/mmy/ispassbidinvitereview",
		type:"post",
		data:{
			strInviteID:iInviteID,
			strAccountState:accountState,
			strAmount:num
		},
		dataType:"text",
		success:function () {
			layer.closeAll();
			var url = "/mmy/backbidinviteindex" ;
			window.location = url;
			$.messager.show({title:'消息',msg:'成功',timeout:3000,});
		},
		error:function () {
			layer.closeAll();
			$.messager.show({title:'消息',msg:'失败',timeout:3000,});
		}
	});	
  });

	}
		else{
		$.ajax({
		url:"/mmy/ispassbidinvitereview",
		type:"post",
		data:{
			strInviteID:iInviteID,
			strAccountState:accountState,
			strAmount:num
		},
		dataType:"text",
		success:function () {
			layer.closeAll();
			var url = "/mmy/backbidinviteindex" ;
			window.location = url;
			$.messager.show({title:'消息',msg:'成功',timeout:3000,});
		
		},
		error:function () {
			layer.closeAll();
			$.messager.show({title:'消息',msg:'失败',timeout:3000,});
		}
	});		
	}	
	
}


